#pragma once
#include <iostream>
#include <mutex>
#include <unordered_map>

#include "util.hpp"

// 在线用户管理类
class online_manager
{
private:
    std::mutex _mutex;
    std::unordered_map<uint64_t, wsserver_t> _hall_user;
    std::unordered_map<uint64_t, wsserver_t> _room_user;

public:
    void enter_game_hall(uint64_t uid, wsserver_t conn)
    {
        std::unique_lock<std::mutex> lock(_mutex);
        _hall_user.insert({uid, conn});
    }
    void enter_game_room(uint64_t uid, wsserver_t conn)
    {
        std::unique_lock<std::mutex> lock(_mutex);
        _room_user.insert({uid, conn});
    }
    void exit_game_hall(uint64_t uid)
    {
        std::unique_lock<std::mutex> lock(_mutex);
        _hall_user.erase(uid);
    }
    void exit_game_hall(uint64_t uid)
    {
        std::unique_lock<std::mutex> lock(_mutex);
        _room_user.erase(uid);
    }
    bool is_exist_hall(uint64_t uid)
    {
        std::unique_lock<std::mutex> lock(_mutex);
        if (_hall_user.find(uid) == _hall_user.end())
        {
            return false;
        }
        return true;
    }
    bool is_exist_game(uint64_t uid)
    {
        std::unique_lock<std::mutex> lock(_mutex);
        if (_hall_user.find(uid) == _hall_user.end())
        {
            return false;
        }
        return true;
    }
};